GtkPadController: Make ring/strip actions be activated with the axis value
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 23 Aug 2016 18:16:02 +0000 (20:16 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Tue, 23 Aug 2016 19:01:45 +0000 (21:01 +0200)
This way these axes may be used in detail by the implementors of pad GActions.

https://bugzilla.gnome.org/show_bug.cgi?id=770026

gtk/gtkpadcontroller.c

index df54d5d49ea02ad45e3c827d3892b16ce55530c0..c1a9af714edb605dae6c1f6c1b2ba105c0d4a31e 100644 (file)
  *   …
  *   pad_controller = gtk_pad_controller_new (window, action_group, NULL);
  * ]|
+ *
+ * The actions belonging to rings/strips will be activated with a parameter
+ * of type %G_VARIANT_TYPE_DOUBLE bearing the value of the given axis, it
+ * is required that those are made stateful and accepting this #GVariantType.
  */
 
 #include "config.h"
@@ -154,6 +158,16 @@ gtk_pad_controller_activate_action (GtkPadController        *controller,
                                   NULL);
 }
 
+static void
+gtk_pad_controller_activate_action_with_axis (GtkPadController        *controller,
+                                              const GtkPadActionEntry *entry,
+                                              gdouble                  value)
+{
+  g_action_group_activate_action (controller->action_group,
+                                  entry->action_name,
+                                  g_variant_new_double (value));
+}
+
 static void
 gtk_pad_controller_handle_mode_switch (GtkPadController *controller,
                                        GdkDevice        *pad,
@@ -253,7 +267,16 @@ gtk_pad_controller_handle_event (GtkEventController *controller,
   if (!entry)
     return GDK_EVENT_PROPAGATE;
 
-  gtk_pad_controller_activate_action (pad_controller, entry);
+  if (event->type == GDK_PAD_RING ||
+      event->type == GDK_PAD_STRIP)
+    {
+      gtk_pad_controller_activate_action_with_axis (pad_controller, entry,
+                                                    event->pad_axis.value);
+    }
+  else
+    {
+      gtk_pad_controller_activate_action (pad_controller, entry);
+    }
 
   return GDK_EVENT_STOP;
 }